#pragma once
#include <memory>
#include <mutex>

template<typename T>
class Singleton
{
public:

    static std::shared_ptr<T> GetInstance(){
        static std::once_flag flag;
        std::call_once(flag,[&](){
            instance_ = std::shared_ptr<T>(new T());
        });
        return instance_;
    }


protected:
    Singleton()=default;
    ~Singleton()=default;
    static std::shared_ptr<T> instance_;
    //禁止拷贝构造和赋值运算符
    Singleton(const Singleton<T>& other)=delete;
    Singleton<T>& operator=(const Singleton<T>& other)=delete;


};

template<typename T>
std::shared_ptr<T> Singleton<T>::instance_=nullptr;
